package com.lcj.OwnerMyBatis.sqlSession;

import com.lcj.OwnerMyBatis.config.XMLConfigBuilder;
import com.lcj.OwnerMyBatis.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Author：liuchangjun
 * @Date：2021/10/26
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {

        //使用dom4j解析配置文件，将解析内容封装到Configuration
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration =xmlConfigBuilder.parseConfig(in);
        //创建sqlSessionFactory:工厂类，生产sqlSession：会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }
}
